#include"mystdio.h"
#include<string.h>
#include<unistd.h>

#define MYFILE "log,txt"

int main()
{
  //打开文件
  MY_FILE*fp=my_fopen(MYFILE,"w");
  if(fp==NULL)
  {
    return 1;
  }
  
  //操作文件
  int cnt=5;
  const char*str="hello fwrite";
  while(cnt)
  {
    char buffer[1024];
    snprintf(buffer,sizeof(buffer),"%s:%d\n",str,cnt--);
    
    sleep(1);

    size_t size=my_fwrite(buffer,strlen(buffer),1,fp);
    printf("当前成功写入%ld个字节\n",size);
  }
  
  //关闭文件
  my_fclose(fp);
}
